<?php
namespace Home\Controller;
use Think\Controller;
class CommonController extends Controller {
    public function _initialize(){
    	header("Content-Type:text/html; charset=utf-8");
		if(session('user_name') == null){
			$url = __APP__."/Login/login";
			echo "<script language='javascript'>parent.location='$url';</script>";exit;
		}
//		if(empty(getenv( "HTTP_REFERER" ))){ //
//			$this->error("无效的URL连接！","__APP__");
//		}
    }
    
    public function systemlog($operat,$modul,$action){//系统日志
    	$log = M("sys_log");
		date_default_timezone_set('PRC');
		$time = date('Y-m-d H:i:s');
		
		$ip = get_client_ip();
		
		if($operat == 'add'){
			$operat = "添加";
		}else if($operat == 'edit'){
			$operat = "修改";
		}else if($operat == 'delete'){
			$operat = "删除";
		}else if($operat == 'upload'){
			$operat = "上传";
		}
		$data = array(
			'user_name'=>session('name'),
			'operat'=>$operat,
			'modul'=>$modul,
			'action'=>session('name').'  '.$action,
			'create_time'=>$time,
			'ip'=>$ip
		);
		$log->add($data);
    }
    
    public function information($title, $content, $user_name){//信息提示
    	$information = M("information");
    	$data = array(
			'title' => $title,
			'content' => $content,
			'url' => '',
			'time' => date("Y-m-d H:i:s"),
			'status' => '1',
			'user_name' => $user_name,
		);
		$information->add($data);
    }
    
  
    public function _empty($name){
    	$this->emptyaction($name);
    }


	public function no_power(){
		echo "<div style='width: 250px;height: 150px;margin: 0 auto; color:red;'>无权限查看</div>";
	}

	public function emptyaction($name){
//		echo APP_PATH;
		E("无此---".$name."操作！");
//		echo "无此".$name."操作！";
	}
}
?>